//
//  OrderListVC.m
//  phmall
//
//  Created by admin on 2017/10/6.
//  Copyright © 2017年 admin. All rights reserved.
//

#import "OrderListVC.h"
#import "Orderheader.h"
#import "OrderCell.h"
#import "EvaluateVC.h"
#import "OrderModel.h"
#import "RefundVC.h"
#import "OrderdetailVC.h"
#import "PaymentView.h"
#import "Ipay88PayVC.h"
#define But_Tag 1000;

@interface OrderListVC ()<UIScrollViewDelegate,UITableViewDelegate,UITableViewDataSource,DZNEmptyDataSetSource,PaymentViewDelegate,DZNEmptyDataSetDelegate,UIWebViewDelegate>
{
    Orderheader *_headView;
    UIScrollView *_scrollView;
    UIImageView *background;
    PaymentView *pay;
    OrderModel *payOrder;
    NSInteger status,start;
}
@property(strong,nonatomic)UITableView *myTableview;
@property(strong,nonatomic)NSMutableArray *orderList;
@property(nonatomic,strong)MBProgressHUD *hud;
@end

@implementation OrderListVC


-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navBarBgAlpha=@"1.0";
    self.navigationController.navigationBar.barTintColor = [UIColor whiteColor];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    status=0;
    start=0;
    [self loadDataWithorder:YES];
    [self setUI];
  
    self.title=Localized(@"订单中心");
    UIBarButtonItem* leftBar=[[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"返回"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStyleDone target:self action:@selector(leftBarAction)];
    self.navigationItem.leftBarButtonItem=leftBar;
    // Do any additional setup after loading the view.

    self.myTableview.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(footeRefresh)];
    self.myTableview.mj_footer.hidden=YES;
    self.myTableview.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(HeaderRefresh)];
}
-(void)HeaderRefresh{
    start=0;
    [self loadDataWithorder:NO];
}
-(void)footeRefresh{
    start=self.orderList.count;
    [self loadDataWithorder:YES];
}
- (void)loadDataWithorder:(BOOL)reload{
    NSString *urlstr =  [NSString stringWithFormat:@"%@%@",HomeURL,@"member_order"];
    if (status==10) {
        urlstr=[NSString stringWithFormat:@"%@%@",HomeURL,@"member_order/scomment"];
    }
    NSMutableDictionary *parametersDic = [NSMutableDictionary dictionary];
    [parametersDic setValue:[NSString stringWithFormat:@"%ld",(long)start] forKey:@"start"];
    [parametersDic setValue:[NSString stringWithFormat:@"%ld",(long)status] forKey:@"status"];
    [httpTool ZBPostNetDataWith:urlstr withDic:parametersDic andSuccess:^(id responseObject) {
        if (start==0) {
            [self.orderList removeAllObjects];
            if (reload) {
                [self.myTableview setContentOffset:CGPointMake(0, 0) animated:NO];
            }
        }
        self.emptyType=EmptyDataSetNoData;
        NSMutableDictionary *responseDict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
        if ([responseDict[@"ret"] isEqualToString:@"200"]) {
            if (responseDict[@"data"] !=[NSNull alloc]) {
                NSMutableArray *data=responseDict[@"data"];
                if (data.count==0) {
                    [self.myTableview.mj_header endRefreshing];
                    [self.myTableview.mj_footer endRefreshingWithNoMoreData];
                    if (reload) {
                        [self.myTableview reloadData];
                    }
                }else{
                    
                    [self analysisDataWithOrderArray:data];
                }
            }
        }else if ([responseDict[@"ret"] isEqualToString:@"202"]) {
            [self.myTableview.mj_header endRefreshing];
            [self.myTableview.mj_footer endRefreshingWithNoMoreData];
            if (self.orderList.count!=0) {
                //数量少于2条时隐藏上拉加载
                if (self.orderList.count<2) {
                    self.myTableview.mj_footer.hidden=YES;
                }else{
                    self.myTableview.mj_footer.hidden=NO;
                }
            }else{
                //数量为0条时隐藏上拉加载
                self.myTableview.mj_footer.hidden=YES;
            }
            if (reload) {
                [self.myTableview reloadData];
            }
        }
        [self.hud hideAnimated:YES];
    } andFailure:^{
        if (self.emptyType==EmptyDataSetNoNetwork) {
            [PublicClass ProgressHUDModeText:Localized(@"网络错误") andTime:2 ];
        }
        self.myTableview.mj_footer.hidden=YES;
        [self.orderList removeAllObjects];
        self.emptyType=EmptyDataSetNoNetwork;
        [self.myTableview reloadData];
        [self.myTableview.mj_header endRefreshing];
        [self.myTableview.mj_footer endRefreshing];
        [self.hud hideAnimated:YES];
    }];
    
}
- (void)analysisDataWithOrderArray:(NSMutableArray *)array{
//    [self.orderList removeAllObjects];
    for (NSDictionary *dict in array)
    {
        OrderModel *model = [OrderModel yy_modelWithDictionary:dict];
        [self.orderList addObject:model];
    }
    if (self.orderList.count!=0) {
        //数量少于2条时隐藏上拉加载
        if (self.orderList.count<2) {
            self.myTableview.mj_footer.hidden=YES;
        }else{
            self.myTableview.mj_footer.hidden=NO;
        }
    }else{
        //数量为0条时隐藏上拉加载
        self.myTableview.mj_footer.hidden=YES;
    }
    [self.myTableview reloadData];
    [self.myTableview.mj_header endRefreshing];
    [self.myTableview.mj_footer endRefreshing];
}
-(void)setUI{
    __weak typeof(self) weakSelf = self;
    _headView = [[Orderheader alloc]init];
    _headView.backgroundColor=[UIColor colorWithHexString:@"#E7EBEE"];
    [self.view addSubview:_headView];
    [_headView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view).offset(0);
        make.left.right.equalTo(self.view);
        make.height.offset(40);
    }];
    _headView.backgroundColor=[UIColor colorWithHexString:@"#f8fafd"];
    _headView.items = @[Localized(@"全部"),Localized(@"待付款"),Localized(@"待发货"),Localized(@"待收货"),Localized(@"待评价")];
    [_headView setSelectAtIndex:self.type+1];
    [self adjustScrollView:self.type+1];
    _headView.itemClickAtIndex = ^(NSInteger index){
        [weakSelf adjustScrollView:index];
    };
    
    [self.view addSubview:self.myTableview];
    [self.myTableview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view).offset(40);
        make.left.right.equalTo(self.view).priorityHigh();
        make.bottom.equalTo(self.view).with.offset(-self.tabBar_height).priorityHigh();
    }];
    
    if (@available(iOS 11.0, *)) {
        self.myTableview.estimatedRowHeight = 0;
        self.myTableview.estimatedSectionFooterHeight = 0;
        self.myTableview.estimatedSectionHeaderHeight = 0;
        self.myTableview.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }
    
}
#pragma mark-通过点击button来改变scrollview的偏移量
-(void)adjustScrollView:(NSInteger)index{
    self.hud=[MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].keyWindow  animated:YES];
    self.hud.detailsLabel.text = Localized(@"加载中...");
    switch (index) {
        case 0:
            status=0;
            start=0;
            [self loadDataWithorder:YES];
            break;
        case 1:
            status=1;
            start=0;
            [self loadDataWithorder:YES];
            break;
        case 2:
            status=3;
            start=0;
            [self loadDataWithorder:YES];
            break;
        case 3:
            status=4;
            start=0;
            [self loadDataWithorder:YES];
            break;
        case 4:
            status=10;
            start=0;
            [self loadDataWithorder:YES];
            break;
        default:
            break;
    }
   
}

#pragma mark - tableView
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 100;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.orderList.count;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    OrderModel *model=self.orderList[section];
    NSMutableArray *data=model.goods_list;
    return data.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 98;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 44;
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 98)];
    view.backgroundColor=[UIColor groupTableViewBackgroundColor];
    OrderModel *model=self.orderList[section];
    NSLog(@"=================%@",model.status_num);
    UIView *back=[[UIView alloc]init];
    back.backgroundColor=[UIColor whiteColor];
    [view addSubview:back];
    [back mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.equalTo(view);
        make.height.offset(88);
    }];
    
    UILabel *price=[[UILabel alloc]init];
    [view addSubview:price];
    price.text=model.goods_amount;
//     price.text=@"₱8888";
    price.font=[UIFont systemFontOfSize:13];
    [price mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(view).offset(-20);
        make.centerY.equalTo(back.mas_centerY).offset(-22);
    }];

    
    UILabel *number=[[UILabel alloc]init];
    [view addSubview:number];
    number.text=[NSString stringWithFormat:@"%@ %@,%@:",model.status_num,Localized(@"件商品"),Localized(@"合计")];
//    number.text=[NSString stringWithFormat:@"共 %@ 件商品,合计(含运费):",@"5"];
    number.font=[UIFont systemFontOfSize:13];
    [number mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(price.mas_left).offset(-10);
        make.centerY.equalTo(price);
    }];
    
    
    UIView *line=[[UIView alloc]init];
    [view addSubview:line];
    line.backgroundColor=[UIColor groupTableViewBackgroundColor];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(view).offset(10);
        make.centerY.equalTo(back);
        make.right.equalTo(view).offset(-10);
        make.height.offset(1);
    }];
    
    
    NSMutableArray *butArr = [NSMutableArray array];
    NSArray *titleArr=[NSArray array];

    switch ([model.status_num intValue]) {
        case 1:
            titleArr=@[Localized(@"取消"),Localized(@"付款")];
            break;
        case 2:
            titleArr=@[Localized(@"删除订单")];
            break;
        case 3:
            titleArr=@[Localized(@"申请退款")];
            break;
        case 4:
            titleArr=@[Localized(@"查看物流"),Localized(@"确认收货")];
            break;
        case 5:
            titleArr=@[Localized(@"申请售后"),Localized(@"评价")];
            break;

        default:
            break;
    }
    for (int i=0; i<titleArr.count; i++) {
        UIButton *but=[UIButton buttonWithType:UIButtonTypeCustom];
        [view addSubview:but ];
        [but setTitle:titleArr[i] forState:UIControlStateNormal];
        if (i==titleArr.count-1) {
            ViewBorderRadius(but, 6, 1, [UIColor colorWithHexString:@"feba03"]);
            [but setTitleColor:[UIColor colorWithHexString:@"feba03"] forState:UIControlStateNormal];
        }else{
            ViewBorderRadius(but, 6, 1, [UIColor blackColor]);
            [but setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        }
        but.tag=20000+section;
        but.titleLabel.numberOfLines = 2;
        but.titleLabel.textAlignment = NSTextAlignmentCenter;
        but.titleLabel.font=[UIFont systemFontOfSize:13];
        [but addTarget:self action:@selector(butAction:) forControlEvents:UIControlEventTouchUpInside];
        
        if (titleArr.count<=1) {
            [but mas_makeConstraints:^(MASConstraintMaker *make) {
                make.centerY.equalTo(back).offset(22);
                make.height.mas_equalTo(30);
                make.right.offset(-10);
                make.width.offset(80);
            }];
        }else{
            [butArr addObject:but];
        }
        
    }
    
    if (butArr.count>1) {
        [butArr mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedItemLength:80 leadSpacing:SCREEN_WIDTH-titleArr.count*90 tailSpacing:10];
        [butArr mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(back).offset(22);
            //        UIView *blueView = (UIView *)blueViews[0];
            make.height.mas_equalTo(30);
        }];
    }

    return view;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 44)];
    view.backgroundColor=[UIColor whiteColor];
    OrderModel *model=self.orderList[section];
   
    UIImageView *icon=[[UIImageView alloc]init];
    [view addSubview:icon];
    icon.image=[UIImage imageNamed:@"店铺-1"];
    [icon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(view).offset(20);
        make.centerY.equalTo(view);
        make.width.height.offset(20);
    }];
    
    UIButton *name=[UIButton buttonWithType:UIButtonTypeCustom];
    [view addSubview:name];
    [name setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [name setTitle:model.shop_name forState:UIControlStateNormal];
    //    [name setTitle:@"lalalanfe" forState:UIControlStateNormal];
    name.titleLabel.font=[UIFont systemFontOfSize:16];
    [name setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    [name mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(icon.mas_right).offset(10);
        make.centerY.equalTo(view);
    }];
    name.contentHorizontalAlignment=UIControlContentHorizontalAlignmentCenter;
    [name layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleRight imageTitleSpace:5];
    
    UILabel *status=[[UILabel alloc]init];
    [view addSubview:status];
    status.text=model.status;
    //    status.text=@"待付款";
    status.textColor=[UIColor colorWithHexString:@"feba03"];
    status.font=[UIFont systemFontOfSize:13];
    [status mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(view).offset(-20);
        make.centerY.equalTo(view);
    }];
    
    UIView *line=[[UIView alloc]init];
    line.backgroundColor=[UIColor groupTableViewBackgroundColor];
    [view addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(view).offset(00);
        make.right.equalTo(view).offset(0);
        make.bottom.equalTo(view);
        make.height.offset(1);
    }];
    
    return view;
}
-(void)butAction:(UIButton *)sender{
    OrderModel *model=self.orderList[sender.tag-20000];
//    RefundVC *refund=[[RefundVC alloc]init];
//    [self.navigationController pushViewController:refund animated:YES];
//    if ([sender.titleLabel.text isEqualToString:NSLocalizedString(@"取消", nil)]) {
//        [self tapAvatarView];
//    }
    if ([sender.titleLabel.text isEqualToString:Localized(@"付款")]) {
        payOrder=model;
        [self PaymentView];
    }
    if ([sender.titleLabel.text isEqualToString:Localized(@"取消")]) {
        [self tapAvatarView:model.uid];
    }
}
//-(void)orderPayment:(OrderModel *)model{
//    NSString *urlstr =  [NSString stringWithFormat:@"%@%@",HomeURL,@"pay"];
//    NSMutableDictionary *parametersDic = [NSMutableDictionary dictionary];
//    //
//    [parametersDic setValue:@"1" forKey:@"advance"];
//    [parametersDic setValue:@"phmall" forKey:@"pay_pass"];
//    [parametersDic setValue:model.pay_id forKey:@"pay_id"];
//    [parametersDic setValue:model.ordersn forKey:@"orderid"];
//
//    [httpTool ZBPostNetDataWith:urlstr withDic:parametersDic andSuccess:^(id responseObject) {
//        self.emptyType=EmptyDataSetNoData;
//        NSMutableDictionary *responseDict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
//        if ([responseDict[@"ret"] doubleValue] == 200) {
//            if (responseDict[@"data"] !=[NSNull alloc]) {
//                NSLog(@"%@",responseDict[@"data"]);
//                if ([responseDict[@"status"] isEqualToString:@"1"]) {
//
//                    [self.navigationController popViewControllerAnimated:YES] ;
//                }else{
//                    [PublicClass ProgressHUDModeText:@"支付失败" andTime:2];
//                }
//            }
//        }
//        [self.hud hideAnimated:YES];
//    } andFailure:^{
//        [self.hud hideAnimated:YES];
//        [PublicClass ProgressHUDModeText:Localized(@"网络错误") andTime:2 ];
//    }];
//}
-(void)loadDataWithOrderDetele:(NSString *)uid{
    
    NSString *urlstr =  [NSString stringWithFormat:@"%@%@",HomeURL,@"member_order/cancel"];
    NSMutableDictionary *parametersDic = [NSMutableDictionary dictionary];
    [parametersDic setObject:uid forKey:@"uid"];
    
    [httpTool ZBPostNetDataWith:urlstr withDic:parametersDic andSuccess:^(id responseObject) {
        self.emptyType=EmptyDataSetNoData;
        
        NSMutableDictionary *responseDict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
        if ([responseDict[@"ret"] isEqualToString:@"200"]) {
            if (responseDict[@"data"] !=[NSNull alloc]) {
                if ([responseDict[@"status"] isEqualToString:@"1"]) {
                    [PublicClass ProgressHUDModeText:@"订单已取消" andTime:2 ];
                    [self loadDataWithorder:YES];
                }
            }
        }else{
            [self userLogout];
            [self.navigationController.tabBarController setSelectedIndex:0];
        }
        
    } andFailure:^{
        
        [PublicClass ProgressHUDModeText:Localized(@"网络错误") andTime:2 ];
    }];
}

-(void)PaymentView{
    if ([payOrder.pay_id isEqualToString:@"16"]) {
        Ipay88PayVC *ipay=[[Ipay88PayVC alloc]init];
        ipay.payOrder=payOrder;
        self.hidesBottomBarWhenPushed=YES;
        [self.navigationController pushViewController:ipay animated:YES];
    }else{
        background=[UIImageView new];
        background.image=[UIImage imageNamed:@"透明图片"];
        [[UIApplication sharedApplication].keyWindow addSubview:background];
        [background mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.top.bottom.offset(0);
        }];
        //    background.hidden=YES;
        UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(close)];
        background.userInteractionEnabled=YES;
        [background addGestureRecognizer:tap];
        
        pay=[[PaymentView alloc]init];
        pay.delegate=self;
        ViewBorderRadius(pay, 10, 0, [UIColor clearColor]);
        [[UIApplication sharedApplication].keyWindow addSubview:pay];
        [pay mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.offset(0);
            make.centerY.offset(-60);
            make.width.offset(280);
            make.height.offset(260);
        }];
    }
}
-(void)close{
    background.hidden=YES;
    pay.hidden=YES;
}
-(void)Passwordill:(NSString *)password{
    [self close];

    self.hud =[MBProgressHUD showHUDAddedTo:self.view  animated:YES];
    self.hud.detailsLabel.text =  Localized(@"加载中...");
    NSString *urlstr =  [NSString stringWithFormat:@"%@%@",HomeURL,@"pay"];
    
    NSMutableDictionary *parametersDic = [NSMutableDictionary dictionary];
    [parametersDic setValue:@"0" forKey:@"advance"];
    [parametersDic setValue:password forKey:@"pay_pass"];
    [parametersDic setValue:@"16" forKey:@"pay_id"];
    [parametersDic setValue:payOrder.ordersn forKey:@"orderid"];
    
    [httpTool ZBPostNetDataWith:urlstr withDic:parametersDic andSuccess:^(id responseObject) {
        self.emptyType=EmptyDataSetNoData;
        NSMutableDictionary *responseDict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
        if ([responseDict[@"ret"] doubleValue] == 200) {
            if (responseDict[@"data"] !=[NSNull alloc]) {
                if ([responseDict[@"status"] isEqualToString:@"1"]) {
                    [PublicClass ProgressHUDModeText:@"支付成功" andTime:2];
                }else{
                    [PublicClass ProgressHUDModeText:@"支付失败" andTime:2];
                }
                
                self.hidesBottomBarWhenPushed=YES;
                OrderdetailVC *evaluate=[[OrderdetailVC alloc]init];
                evaluate.ordersn=payOrder.ordersn;
                [self.navigationController pushViewController:evaluate animated:YES];
                
            }
        }
        [self.hud hideAnimated:YES];
    } andFailure:^{
        [self.hud hideAnimated:YES];
        [PublicClass ProgressHUDModeText:Localized(@"网络错误") andTime:2 ];
    }];

}

-(void)tapAvatarView:(NSString *)uid{

    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    [alertController addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
    }]];
    [alertController addAction:[UIAlertAction actionWithTitle:@"我不想买了" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [self loadDataWithOrderDetele:uid];
    }]];
    [alertController addAction:[UIAlertAction actionWithTitle:@"信息填错,重新拍" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [self loadDataWithOrderDetele:uid];
    }]];
    [alertController addAction:[UIAlertAction actionWithTitle:@"卖家迟迟不发货" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [self loadDataWithOrderDetele:uid];
    }]];
    [alertController addAction:[UIAlertAction actionWithTitle:@"误点错拍" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [self loadDataWithOrderDetele:uid];
    }]];
    [alertController addAction:[UIAlertAction actionWithTitle:@"其他原因" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [self loadDataWithOrderDetele:uid];
    }]];
    
    [self.navigationController presentViewController:alertController animated:YES completion:nil];
    
}


-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    OrderCell *cell=[OrderCell theShareCellWithTableView:tableView];
    OrderModel *model=self.orderList[indexPath.section];
    NSMutableArray *data=model.goods_list;
    GoodsListModel *goodsModel=data[indexPath.row];
    NSLog(@"%@",[NSString stringWithFormat:@"%@union/%@",IMGURL,goodsModel.goods_file]);
    cell.model=goodsModel;
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    self.hidesBottomBarWhenPushed=YES;
    OrderdetailVC *evaluate=[[OrderdetailVC alloc]init];
    OrderModel *model=self.orderList[indexPath.section];
    evaluate.ordersn=model.ordersn;
    [self.navigationController pushViewController:evaluate animated:YES];
    
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
    } else {
        return YES;
    }
}

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
    //分割线补全
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]){
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }
}
#pragma mark  DZNEmptyDataSetDelegate
- (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView {
    switch (self.emptyType) {
        case EmptyDataSetNone:
            return nil;
            break;
        case EmptyDataSetNoData:
            return [UIImage imageNamed:@"订单缺失"];
            break;
        case EmptyDataSetNoNetwork:
            
            return [UIImage imageNamed:@"断网"];
            break;
    }
}
- (UIView *)customViewForEmptyDataSet:(UIScrollView *)scrollView {
    if (self.emptyType==EmptyDataSetNone) {
        UIActivityIndicatorView *activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
        [activityView startAnimating];
        return activityView;
    }else{
        return nil;
    }
    
}

- (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView{
    
    switch (self.emptyType) {
        case EmptyDataSetNone:
            return NO;
            break;
        case EmptyDataSetNoData:
            return YES;
            break;
        case EmptyDataSetNoNetwork:
            return NO;
            break;
    }
    return YES;
}
- (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView {
    return 0;
}
- (NSAttributedString *)descriptionForEmptyDataSet:(UIScrollView *)scrollView {
    
    if (self.emptyType==EmptyDataSetNoData) {
        NSMutableAttributedString *currentPriceStr = [[NSMutableAttributedString alloc] initWithString:@"你还没有相关的订单！\n可以去看看有哪些想买的。"];
        [currentPriceStr addAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"Georgia-Bold" size:20],NSForegroundColorAttributeName:[UIColor colorWithHexString:@"#E6963F"]} range:NSMakeRange(0, 10)];
        [currentPriceStr addAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"Georgia-Bold" size:18],NSForegroundColorAttributeName:[UIColor colorWithHexString:@"#C2AA93"]} range:NSMakeRange(10, 12)];
        return currentPriceStr;
    }
    if (self.emptyType==EmptyDataSetNoNetwork){
        NSMutableAttributedString *currentPriceStr = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@\n%@",Localized(@"您的网络不给力啊!"),Localized(@"请您检查是否联网。")]];
        [currentPriceStr addAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"Georgia-Bold" size:22],NSForegroundColorAttributeName:[UIColor colorWithHexString:@"#E6963F"]} range:NSMakeRange(0, [Localized(@"您的网络不给力啊!") length])];
        [currentPriceStr addAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"Georgia-Bold" size:18],NSForegroundColorAttributeName:[UIColor colorWithHexString:@"#C2AA93"]} range:NSMakeRange([Localized(@"您的网络不给力啊!") length], [Localized(@"请您检查是否联网。") length])];
        return currentPriceStr;
    }
    return nil;
}
- (NSAttributedString *)buttonTitleForEmptyDataSet:(UIScrollView *)scrollView forState:(UIControlState)state {
    
    if (self.emptyType==EmptyDataSetNoNetwork){
        NSMutableAttributedString *currentPriceStr = [[NSMutableAttributedString alloc] initWithString:Localized(@"重新加载")];
        [currentPriceStr addAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"Georgia-Bold" size:18],NSForegroundColorAttributeName:[UIColor whiteColor]} range:NSMakeRange(0, [Localized(@"重新加载") length])];
        return currentPriceStr;
    }else{
        return nil;
    }
    
}

#pragma mark - DZNEmptyDataSetDelegate

- (void)emptyDataSet:(UIScrollView *)scrollView didTapButton:(UIButton *)button {
    start=0;
    [self loadDataWithorder:YES];
    self.hud=[MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].keyWindow  animated:YES];
    self.hud.detailsLabel.text =  Localized(@"加载中...");
}

- (void)emptyDataSetWillAppear:(UIScrollView *)scrollView {
    self.myTableview.contentOffset = CGPointZero;
}

//MARK:-GETTER
- (UITableView *)myTableview{
    if (!_myTableview) {
        _myTableview = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        _myTableview.delegate = self;
        _myTableview.dataSource = self;
        _myTableview.backgroundColor=[UIColor groupTableViewBackgroundColor];
        _myTableview.separatorStyle = UITableViewCellSeparatorStyleNone;
        _myTableview.showsVerticalScrollIndicator=NO;
        _myTableview.scrollEnabled = YES;
        _myTableview.emptyDataSetSource=self;
        _myTableview.emptyDataSetDelegate=self;
    }
    return _myTableview;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(NSMutableArray *)orderList{
    if (!_orderList) {
        _orderList=[[NSMutableArray alloc] init];
    }
    return _orderList;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
